package com.example.hotelmanagement.controller;

import com.example.hotelmanagement.entity.Booking;
import com.example.hotelmanagement.service.BookingService;
import com.example.hotelmanagement.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bookings")
public class BookingController {

    @Autowired
    private BookingService bookingService;

    // 获取所有预订
    @GetMapping
    public ResponseResult<List<Booking>> getAllBookings() {
        List<Booking> bookings = bookingService.getAllBookings();
        return new ResponseResult<>(200, "Success", bookings);
    }

    // 根据 ID 获取单个预订
    @GetMapping("/{id}")
    public ResponseResult<Booking> getBookingById(@PathVariable Long id) {
        Booking booking = bookingService.getBookingById(id);
        return new ResponseResult<>(200, "Success", booking);
    }

    // 创建新预订
    @PostMapping
    public ResponseResult<Void> createBooking(@RequestBody Booking booking) {
        bookingService.createBooking(booking);
        return new ResponseResult<>(201, "Booking Created", null);
    }

    // 更新预订
    @PutMapping("/{id}")
    public ResponseResult<Void> updateBooking(@PathVariable Long id, @RequestBody Booking booking) {
        booking.setId(id);
        bookingService.updateBooking(id, booking);
        return new ResponseResult<>(200, "Booking Updated", null);
    }

    // 删除预订
    @DeleteMapping("/{id}")
    public ResponseResult<Void> deleteBooking(@PathVariable Long id) {
        bookingService.deleteBooking(id);
        return new ResponseResult<>(200, "Booking Deleted", null);
    }
}
